import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: lishuo
 * Date: 2023-12-17
 * Time: 9:14
 */
public class RedisList {

    public static void test1(Jedis jedis) {
        System.out.println("lpush/rpush/lrange");

        jedis.flushAll();
        jedis.lpush("key1","111","222","333");
        List<String> lreslult1 = jedis.lrange("key1",0,-1);
        System.out.println("lresult = "+lreslult1);

        jedis.flushAll();
        jedis.rpush("key1","111","222","333");
        List<String> rresult = jedis.lrange("key1",0, -1);
        System.out.println("rresult = "+rresult);
    }

    public static void test2(Jedis jedis) {
        System.out.println("lpop/rpop");

        jedis.flushAll();
        jedis.rpush("key1","111","222","333");
        String popkey1 = jedis.rpop("key1");
        System.out.println("popkey1 = "+popkey1);

        String popkey2 = jedis.rpop("key1");
        System.out.println("popkey2 = "+popkey2);

        String popkey3 = jedis.rpop("key1");
        System.out.println("popkey3 = "+popkey3);

        String popkey4 = jedis.rpop("key1");
        System.out.println("popkey4 = "+popkey4);

        System.out.println("-------------------");

        jedis.rpush("key1","111","222","333");
        String key1 = jedis.lpop("key1");
        System.out.println("result1 = "+key1);

        String key2 = jedis.lpop("key1");
        System.out.println("result2 = "+key2);

        String key3 = jedis.lpop("key1");
        System.out.println("result3 = "+key3);

        String key4 = jedis.lpop("key1");
        System.out.println("result4 = "+key4);
    }

    public static void test3(Jedis jedis) {
        System.out.println("blpop");

        jedis.flushAll();
        List<String> result = jedis.blpop(300, "key1");
        System.out.println("result = "+result);
    }

    public static void test4(Jedis jedis) {
        System.out.println("llen");

        jedis.flushAll();
        jedis.lpush("key1","111","222","333","444","555");
        long len = jedis.llen("key1");
        System.out.println("len = "+len);
    }

    public static void main(String[] args) {
        JedisPool jedisPool = new JedisPool("tcp://127.0.0.1:6379");
        try (Jedis jedis = jedisPool.getResource()) {
//            test1(jedis);
//            test2(jedis);
//            test3(jedis);
            test4(jedis);
        }

    }
}
